package com.dinggao.crossgo.module.roadbook.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dinggao.crossgo.R;
import com.dinggao.crossgo.module.roadbook.data.RoadBookSubListBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class RoadBookSubListAdapter extends BaseQuickAdapter<RoadBookSubListBean.DataBean, BaseViewHolder> {

    public RoadBookSubListAdapter(@Nullable List<RoadBookSubListBean.DataBean> data) {
        super(R.layout.item_road_book_sub_list, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RoadBookSubListBean.DataBean item) {

        Glide.with(mContext)
                .load(R.drawable.sublist_image)
                //.load("https://home.sddgxx.com/img/pic/roadBookJournal/6c70fc56cfe74882ad3148ba158f4fd1.png")
                .apply(new RequestOptions()
                        .placeholder(R.drawable.sublist_image))
                .into((ImageView) helper.getView(R.id.road_book_sub_bg));

        helper.setText(R.id.road_book_sub_create_time, timeslash(item.getTime()))
                .setText(R.id.road_book_sub_position_tv, item.getLocation())
                .setText(R.id.road_book_sub_title, item.getContent());

        if (item.getAttachment() != null) {
           // List<String> imagelist = (List<String>) item.getAttachment().get(helper.getLayoutPosition()).getImg();
            RequestOptions options = new RequestOptions()
                    .placeholder(R.drawable.sublist_image)
                    .error(R.drawable.sublist_image)
                    .centerCrop();
            Glide.with(mContext)
                    .load("https://home.sddgxx.com/" + item.getAttachment().get(0).getImg())
                    //.load("https://home.sddgxx.com/img/pic/roadBookJournal/6c70fc56cfe74882ad3148ba158f4fd1.png")
                    .apply(options)
                    .into((ImageView) helper.getView(R.id.road_book_sub_bg));
        }


        helper.getView(R.id.sublist_jd).setVisibility(View.GONE);
        helper.getView(R.id.sublist_ydq).setVisibility(View.GONE);
        helper.getView(R.id.sublist_tcq).setVisibility(View.GONE);
        helper.getView(R.id.sublist_jyz).setVisibility(View.GONE);
        helper.getView(R.id.sublist_xsj).setVisibility(View.GONE);

        if (item.getTab().contains("景点")) {
            helper.getView(R.id.sublist_jd).setVisibility(View.VISIBLE);
        }

        if (item.getTab().contains("营地区")) {
            helper.getView(R.id.sublist_ydq).setVisibility(View.VISIBLE);
        }

        if (item.getTab().contains("停车区")) {
            helper.getView(R.id.sublist_tcq).setVisibility(View.VISIBLE);
        }

        if (item.getTab().contains("加油站")) {
            helper.getView(R.id.sublist_jyz).setVisibility(View.VISIBLE);

        }
        if (item.getTab().contains("洗手间")) {
            helper.getView(R.id.sublist_xsj).setVisibility(View.VISIBLE);

        }
    }

    /**
     * 调用此方法输入所要转换的时间戳输入例如（1402733340）输出（"2014年06月14日16时09分00秒"）
     * @param time
     * @return
     */
    /**
     * @param
     * @return
     */
    public static String timeslash(long time) {
        SimpleDateFormat sdr = new SimpleDateFormat("MM/dd HH:mm");
        String times = sdr.format(new Date(time));
        return times;

    }
}
